//
//  MainViewController.swift
//  Weibo
//
//  Created by mac on 15/11/26.
//  Copyright © 2015年 zsl. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //将系统的tabBar 替换为自定义的mainTabBar 系统的tabBar是只读属性,不可以直接操作
        let mainTabBar = MainTabBar()
        
        //通过Kvc 机制动态的修改tabBar的身份
        setValue(mainTabBar, forKey: "tabBar")
        print(tabBar.classForCoder)
        
     addChildViewControllers()
        
    }
    //创建自控制器
    private func addChildViewControllers (){
        
        //self.tabBar.tintColor = UIColor.orangeColor()
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    
    }
    
    //设置addChildViewController
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }

}


